package com.summer.safe.controller.system;


import com.summer.safe.base.BaseController;
import com.summer.safe.utils.Global;
import com.wf.captcha.ArithmeticCaptcha;
import com.wf.captcha.base.Captcha;
import com.wf.captcha.utils.CaptchaUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 图片验证码
 * 
 */
@Controller
@RequestMapping("/kaptcha")
public class CaptchaController extends BaseController {
    @RequestMapping("")
    public void captcha(HttpServletRequest request, HttpServletResponse response) throws Exception {
        Captcha captcha = new ArithmeticCaptcha();
        HttpSession session = request.getSession();
        /**
         * 生成验证码字符串并保存到session中
         */
        String createText = captcha.text();  // 获取运算的结果
        session.setAttribute(Global.KAPTCHA_SESSION_KEY, createText);

        CaptchaUtil.out(captcha,request,response);
    }

}